<!DOCTYPE html>
<html>
    <head>
        <title>UTests for API entry points</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" src="/api.be/utjs/Reg.js"></script>
        <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"></script>
        <script type="text/javascript" src="/api.be/utjs/TestEntryPoint.js"></script>
    </head>
    <body>
        <h4>Please run the test in the firebug...</h4>
        <p>View results in the console.</p>
        <script type="text/javascript">
        <!--
       
       
        /**
         *----------------------------------------------------------------------
         * Collection of one (uncomment and run one per entity at the time)
         */
        
        /**
         * Single entity/getter
         */
        var $assembly = new TestEntryPoint('/api.be/assembly.json?id=123', 'assembly.json'); // entity assembly
        $assembly.expectEqual('/meta/request/entity', 'assembly.json');
        $assembly.expectEqual('/result/id', "123");
        $assembly.expectEqual('/result/title', "6 Seats");
        $assembly.expectEqual('/result/fk_module_id', "100056");
        $assembly.expectInData(null);
        Reg.instance().set($assembly.alias, $assembly, true);
        $assembly.run();

        // CASE: Multiple entities/collection of (incl. collection of 1)
        //var $assemblies = new TestEntryPoint('/api.be/assemblies.json?ids=123,126', 'assemblies.json'); // entity assemblies
        //$assemblies.expectEqual('/meta/request/entity', 'assemblies.json');
        //$assemblies.expectInData({'123' : '6 Seats', '126' : 'Digital Security With Alarm', 'count' : 2});
        //Reg.instance().set($assemblies.alias, $assemblies, true);
        //$assemblies.run();               
        
        // CASE: Filtered by fk_module_id
        var $assemblies = new TestEntryPoint('/api.be/assemblies.json?fk_module_id=100004', 'assemblies.json'); // entity assemblies
        $assemblies.expectEqual('/meta/request/entity', 'assemblies.json');
        $assemblies.expectInData({'4' : 'Manual Air Conditioning', '5' : 'Auto Air Conditioning', 'count' : 2});
        Reg.instance().set($assemblies.alias, $assemblies, true);
        $assemblies.run();               
        
        // CASE: Like search - here programs
        var $programs = new TestEntryPoint('/api.be/programs.json?like=title:F1', 'programs.json'); // entity assemblies
        $programs.expectEqual('/meta/request/entity', 'programs.json');
        $programs.expectInData({'2' : 'F16', '1' : 'Ford F150', 'count' : 2});
        Reg.instance().set($programs.alias, $programs, true);
        $programs.run();               
        
        // CASE: Collection of 1
        //var $assemblies2 = new TestEntryPoint('/api.be/assemblies.json?ids=123', 'assemblies.json');
        //$assemblies2.expectEqual('/meta/request/entity', 'assemblies.json');
        //$assemblies2.expectInData({'123' : '6 Seats', 'count' : 2});
        //Reg.instance().set($assemblies2.alias, $assemblies2, true);
        //$assemblies2.run();

        // CASE: Incorrect call
        //var $assemblies3 = new TestEntryPoint('/api.be/assemblies.json?id=123', 'assemblies.json');
        //$assemblies3.expectEqual('/meta/request/entity', 'assemblies.json');
        //$assemblies3.expectEqual('/error', true);
        //$assemblies3.expectEqual('/message', 'Empty or broken list of IDs');
        //Reg.instance().set($assemblies3.alias, $assemblies3, true);
        //$assemblies3.run();            
        
        
        // -->
        </script>
    </body>
</html>
